package operate;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddBook implements MyInterface { //添加图书
    public void work(BookList bookList) {
        System.out.println("添加图书");
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入书名：");
        String name = sc.nextLine();
        System.out.println("请输入作者：");
        String author = sc.nextLine();
        System.out.println("请输入价格：");
        double price = sc.nextDouble();
        System.out.println("请输入类型：");
        String me = sc.nextLine();
        String type = sc.nextLine();

        Book book = new Book(name, author, price, type);

        int countSize = bookList.getUsedSize();

        for (int i = 0; i < countSize; i++) {
            Book book2 = bookList.getBook(i);
            if (book2.getName().equals(name)) {
                System.out.println("已有这本书，无法添加");
                return;
            }
        }
        bookList.setBook(countSize,book);
        bookList.setUsedSize(countSize+1);
        System.out.println("添加成功");
        System.out.println(bookList.getBook(countSize));
    }
}
